package twilight.companion.entity.projectile;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.EntityHitResult;
import net.minecraft.world.phys.HitResult;
import twilight.companion.entity.MiniYetiEntity;
import twilightforest.entity.projectile.IceBomb;

public class MiniYetiIceBomb extends IceBomb {

    public MiniYetiIceBomb(EntityType<? extends IceBomb> type, Level level) {
        super(type, level);
    }

    public MiniYetiIceBomb(EntityType<? extends IceBomb> type, Level level, LivingEntity shooter) {
        super(type, level, shooter);
    }

    @Override
    protected void onHitEntity(EntityHitResult result) {
        Entity hitEntity = result.getEntity();

        if (hitEntity instanceof MiniYetiEntity hitYeti && this.getOwner() instanceof MiniYetiEntity shooterYeti) {
            if (hitYeti.isTame() && shooterYeti.isTame() && 
                hitYeti.getOwner() == shooterYeti.getOwner()) {
                return;
            }
        }
        super.onHitEntity(result);
    }

    @Override
    protected void onHit(HitResult result) {
        if (result instanceof EntityHitResult entityHit) {
            Entity hitEntity = entityHit.getEntity();
            if (hitEntity instanceof MiniYetiEntity hitYeti && this.getOwner() instanceof MiniYetiEntity shooterYeti) {
                if (hitYeti.isTame() && shooterYeti.isTame() && 
                    hitYeti.getOwner() == shooterYeti.getOwner()) {
                    return;
                }
            }
        }
        super.onHit(result);
    }
}